<?php
/**
 * GioCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@ninhgio.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2010-2011 GioCMS (http://cms.ninhgio.com)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @author		NinhGio - ninhgio@gmail.com
 * @since		1.0
 * @version		$Id:$
 */

$this->headTitle($this->TRANSLATOR->translator('page_add_page_title') . ' - ' . $this->TRANSLATOR->translator('common_admin_title', 'core'));
$this->headScript('js/ckeditor/ckeditor.js')
	 ->headScript('js/gio/util.js')
	 ->headScript($this->APP_STATIC_SERVER . '/modules/core/js/editor.js');
?>
<div class="content">
	<div class="box header mb0">
		<div class="head"><div></div></div>
		<h2 class="g_a_breadcump">
			<a class="fl" href="<?php echo $this->url('core_dashboard_index'); ?>"><?php echo $this->TRANSLATOR->translator('dashboard_breadcump', 'core'); ?></a>
			<small class="icon arrow_right" style="display: block;"></small>
			<a class="fl" href="<?php echo $this->url('page_page_list'); ?>"><?php echo $this->TRANSLATOR->translator('page_breadcump'); ?></a>
			<small class="icon arrow_right" style="display: block;"></small>
			<a class="fl" href="javascript: void(0);"><?php echo $this->TRANSLATOR->translator('page_add_breadcump'); ?></a>
			<div class="clear"></div>
		</h2>
	</div>
</div>
<div class="content">
	<div class="desc">
		<div class="body">
			<!--  -->
			<form action="<?php echo $this->url('page_page_add'); ?>" method="post" id="gPagePageAdd">
				<h4 class="g_a_h4 fl"><?php echo $this->TRANSLATOR->translator('page_add_guide'); ?></h4>
				<div class="fr">
					<?php if ($this->ACL->isAllowed('add', 'page', 'page')) : ?>
					<a class="fl g_a_tip form_submit g_a_submit_button mr5" href="javascript: void(0);" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('page_button_save_title')); ?>"></a>
					<?php endif; ?>
					<a class="fl g_a_tip g_a_cancel_button mr5" href="javascript: history.go(-1);" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('common_back_button', 'core')); ?>"></a>
					<?php if ($this->ACL->isAllowed('list', 'page', 'page')) : ?>
					<a class="fl g_a_tip" href="<?php echo $this->url('page_page_list'); ?>" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('page_actions_list_title')); ?>">
						<img src="<?php echo $this->APP_RESOURCE_SERVER; ?>/templates/<?php echo $this->APP_TEMPLATE; ?>/skins/<?php echo $this->APP_SKIN; ?>/images/actions_list_icon.png" style="padding: 0 5px 0 0;" />
					</a>
					<?php endif; ?>
				</div>
				<div class="g_a_line"></div>
				<p>
					<label for="simple_input"><?php echo $this->TRANSLATOR->translator('page_name'); ?></label>
					<input title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('page_name_description')); ?>" type="text" class="text w_20 g_a_tip_right" name="page[name]" id="name" value="<?php if (isset($this->pageData['name'])) : ?><?php echo $this->pageData['name']; ?><?php endif; ?>" />
					<?php if (isset($this->errorMessages) && isset($this->errorMessages['name'])) : ?>
					<span class="g_a_error"><?php echo $this->TRANSLATOR->translator($this->errorMessages['name']); ?></span>
					<?php endif; ?>
					<br>
				</p>
				<p class="small">&nbsp;</p>
				<p>
					<label for="simple_input"><?php echo $this->TRANSLATOR->translator('page_slug'); ?></label>
					<input title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('page_slug_description')); ?>" type="text" class="text w_20 g_a_tip_right" name="page[slug]" id="slug" value="<?php if (isset($this->pageData['slug'])) : ?><?php echo $this->pageData['slug']; ?><?php endif; ?>" />
					<?php if (isset($this->errorMessages) && isset($this->errorMessages['slug'])) : ?>
					<span class="g_a_error"><?php echo $this->TRANSLATOR->translator($this->errorMessages['slug']); ?></span>
					<?php endif; ?>
					<br>
				</p>
				<p class="small">&nbsp;</p>
				<p>
					<label for="simple_input"><?php echo $this->TRANSLATOR->translator('page_language'); ?></label>
					<?php echo Modules_Core_Services_Language::languageSelect(array(
																			'name' => 'page[language]', 
																			'id' => 'languageSelector', 
																			'selected' => $this->lang)); ?>
					<?php if (isset($this->errorMessages) && isset($this->errorMessages['language'])) : ?>
					<span class="g_a_error"><?php echo $this->TRANSLATOR->translator($this->errorMessages['language']); ?></span>
					<?php endif; ?>						
					<br>
				</p>
				<p class="small">&nbsp;</p>
				<p>
					<label for="simple_input"><?php echo $this->TRANSLATOR->translator('page_source_item'); ?></label>
					<div class="g_a_translatable">
						<?php echo Modules_Page_Services_Page::translatablePage(array(
																						'name' => 'page[source_item]', 
																						'id' => 'page_source_item',
																						'selected' => (null == $this->sourcePage) ? null : $this->sourcePage['page_id'],
																						'disabled' => (null == $this->sourcePage) ? null : $this->sourcePage['page_id']), $this->lang); ?>
						</div>					
					<br>
				</p>
				<p class="small">&nbsp;</p>
				<p>
					<label for="simple_input"><?php echo $this->TRANSLATOR->translator('page_parent'); ?></label>
					<div class="g_a_translatable">
						<?php echo Modules_Page_Services_Page::pageSelect(array(
																					'name' => 'page[parent_id]', 
																					'id' => 'page_parent_id'), $this->lang); ?>
					</div>					
					<br>
				</p>
				<p class="small">&nbsp;</p>
				<p class="news-article-content">
					<label for="simple_input"><?php echo $this->TRANSLATOR->translator('page_description'); ?></label>
					<?php if (isset($this->errorMessages) && isset($this->errorMessages['description'])) : ?>
					<span class="g_a_error"><?php echo $this->TRANSLATOR->translator($this->errorMessages['description']); ?></span><br />
					<?php endif; ?>
					<textarea name="page[description]" id="description" class="g_a_ui_editor" style="width: 98%; height: 200px"><?php if (isset($this->pageData['description'])) : ?><?php echo $this->pageData['description']; ?><?php endif; ?></textarea>
					<br>
				</p>
				<p class="small">&nbsp;</p>
				<p class="news-article-content">
					<label for="simple_input"><?php echo $this->TRANSLATOR->translator('page_content'); ?></label>
					<?php if (isset($this->errorMessages) && isset($this->errorMessages['content'])) : ?>
					<span class="g_a_error"><?php echo $this->TRANSLATOR->translator($this->errorMessages['content']); ?></span><br />
					<?php endif; ?>
					<textarea name="page[content]" id="content" class="g_a_ui_editor"><?php if (isset($this->pageData['content'])) : ?><?php echo $this->pageData['content']; ?><?php endif; ?></textarea>
					<br>
				</p>
				<p class="small">&nbsp;</p>
				<p>
					<label for="simple_input"><?php echo $this->TRANSLATOR->translator('page_status'); ?></label>
					<select class="g_a_tip_right" id="status" name="page[status]" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('page_status_description')); ?>">
						<option value="inactive"<?php if (isset($this->pageData) && $this->pageData['status'] == 'inactive') : ?> selected="selected"<?php endif; ?>><?php echo $this->TRANSLATOR->translator('page_status_inactive'); ?></option>
						<option value="active"<?php if (isset($this->pageData) && $this->pageData['status'] == 'active') : ?> selected="selected"<?php endif; ?>><?php echo $this->TRANSLATOR->translator('page_status_active'); ?></option>
					</select>
					<br>
				</p>
				<p class="small">&nbsp;</p>
				
				<p class="last buttons_demo">
					<?php if ($this->ACL->isAllowed('add', 'page', 'page')) : ?>
					<a class="button form_submit green" href="<?php echo $this->url('page_page_add'); ?>"><small class="icon check"></small><span><?php echo $this->TRANSLATOR->translator('common_submit_button', 'core'); ?></span></a>
					<?php endif; ?>
					<a class="button red" href="javascript: history.go(-1);"><small class="icon cross"></small><span><?php echo $this->TRANSLATOR->translator('common_back_button', 'core'); ?></span></a>
					<?php if (isset($this->tokenElement)) : ?><?php echo $this->tokenElement; ?><?php endif; ?>
				</p>
			</form>
			<!--  -->
			<div class="clear"></div>
		</div>
	</div>
	<div class="body_footer">
		<div class="bottom_left"><div class="bottom_right"></div></div>
	</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
	<?php if (($string = $this->MESSENGER->printMessages()) != null) : ?>
	Gio.Message.success('<?php echo $string; ?>');
	<?php endif; ?>
	
	CKEDITOR.replace('page[description]', {
		toolbar :
		[
			['Source' , '-', 'Bold', 'Italic', 'Link', '-', 'About']
		],
		width: 900,
		height: 120,
		language: 'vi',
		contentsCss: '<?php echo $this->APP_RESOURCE_SERVER; ?>/templates/<?php echo $this->frontendTemplate; ?>/skins/<?php echo $this->frontendSkin; ?>/style.css'
	});

	CKEDITOR.replace('page[content]', { 
		height: 350,
		width: 900,
		language: 'vi',
		contentsCss: '<?php echo $this->APP_RESOURCE_SERVER; ?>/templates/<?php echo $this->frontendTemplate; ?>/skins/<?php echo $this->frontendSkin; ?>/style.css'
	});

	/**
	 * Automatically create slug once user enter the title
	 */
	$('#name').bind('change', function() {
		$('#slug').val(Gio.Util.generateSlug($(this).val()));
	});
});
</script>